package com.aspose.cells.b.a.b;

import com.aspose.cells.ImageFormat;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.image.Raster;
import java.util.Iterator;
import javax.imageio.IIOException;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;

public class za extends zj {
   public za(BufferedImage var1, ImageFormat var2) {
      super(var1, var2);
   }

   public za(zj var1) {
      this(var1, var1.m());
   }

   public za(zj var1, zs var2) {
      this(var1, var2.b(), var2.c());
   }

   public za(zj var1, int var2, int var3) {
      super(a(var1, var2, var3), ImageFormat.getMemoryBmp());
   }

   public za(int var1, int var2) {
      this(var1, var2, 2498570);
   }

   public za(int var1, int var2, int var3) {
      super(new BufferedImage(var1, var2, c(var3)), ImageFormat.getBmp());
   }

   public za(String var1) throws Exception {
      this((com.aspose.cells.b.a.d.zm)(new com.aspose.cells.b.a.d.ze(var1, 3, 1, 1)), (ImageFormat)b(var1));
   }

   public za(com.aspose.cells.b.a.d.zm var1) throws Exception {
      ImageInputStream var2 = ImageIO.createImageInputStream(var1.g());
      Iterator var3 = ImageIO.getImageReaders(var2);
      if (var3.hasNext()) {
         ImageReader var4 = (ImageReader)var3.next();
         String var5 = var4.getFormatName();
         ImageFormat var6 = ImageFormat.a(var5);
         BufferedImage var7 = null;

         try {
            var7 = ImageIO.read(var2);
         } catch (IIOException var12) {
            var4.setInput(ImageIO.createImageInputStream(var1.g()));
            Raster var9 = var4.readRaster(0, (ImageReadParam)null);
            var7 = new BufferedImage(var9.getWidth(), var9.getHeight(), 2);
            var7.setData(var9);
            BufferedImage var10 = new BufferedImage(var7.getWidth(), var7.getHeight(), 5);
            Graphics2D var11 = var10.createGraphics();
            var11.drawImage(var7, 0, 0, (ImageObserver)null);
            var11.dispose();
            var7 = var10;
         } catch (Exception var13) {
            throw var13;
         }

         if (!var6.equals(ImageFormat.getJpeg()) && var7.getType() != 1) {
            BufferedImage var8 = new BufferedImage(var7.getWidth(), var7.getHeight(), 1);
            Graphics2D var14 = var8.createGraphics();
            var8 = var14.getDeviceConfiguration().createCompatibleImage(var7.getWidth(), var7.getHeight(), 3);
            var14.dispose();
            var14 = var8.createGraphics();
            var14.drawImage(var7, 0, 0, (Color)null, (ImageObserver)null);
            var14.dispose();
            var7 = var8;
         }

         this.a(var7, var6);
      } else {
         throw new Exception("invalid image stream or image format is not supported.");
      }
   }

   public za(com.aspose.cells.b.a.d.zm var1, ImageFormat var2) throws Exception {
      ImageInputStream var3 = ImageIO.createImageInputStream(var1.g());
      BufferedImage var4 = ImageIO.read(var3);
      this.a(var4, var2);
   }

   public zj a() {
      BufferedImage var1 = new BufferedImage(this.a.getWidth(), this.a.getHeight(), this.a.getType());
      var1.setData(this.a.getData());
      return new za(var1, this.b);
   }

   public void b() {
      super.b();
   }

   public com.aspose.cells.Color a(int var1, int var2) {
      return com.aspose.cells.Color.fromArgb(this.a.getRGB(var1, var2));
   }

   public void a(int var1, int var2, com.aspose.cells.Color var3) {
      this.a.setRGB(var1, var2, var3.toArgb());
   }

   private static int c(int var0) {
      switch(var0) {
      case 65536:
         return 13;
      case 135173:
         return 9;
      case 135174:
         return 8;
      case 139273:
         return 1;
      case 196865:
         return 10;
      case 925707:
         return 3;
      case 1052676:
         return 11;
      case 2498570:
         return 2;
      default:
         return 2;
      }
   }

   public int c() {
      int var1 = this.a.getType();
      switch(var1) {
      case 1:
         return 139273;
      case 2:
         return 2498570;
      case 3:
         return 925707;
      case 4:
      case 6:
      case 7:
      case 12:
      default:
         return 0;
      case 5:
         return 137224;
      case 8:
         return 135174;
      case 9:
         return 135173;
      case 10:
         return 196865;
      case 11:
         return 1052676;
      case 13:
         return 65536;
      }
   }

   private static BufferedImage a(zj var0, int var1, int var2) {
      Image var3 = var0.f().getScaledInstance(var1, var2, 1);
      BufferedImage var4 = new BufferedImage(var3.getWidth((ImageObserver)null), var3.getHeight((ImageObserver)null), 2);
      Graphics2D var5 = var4.createGraphics();
      var5.drawImage(var3, 0, 0, (ImageObserver)null);
      var5.dispose();
      return var4;
   }

   private static ImageFormat b(String var0) {
      int var1 = var0.lastIndexOf(".");
      if (var1 == -1) {
         return ImageFormat.getBmp();
      } else {
         String var2 = var0.substring(var1 + 1);
         ImageFormat var3 = ImageFormat.getImageFormatFromSuffixName(var2);
         return var3 == null ? ImageFormat.getEmf() : var3;
      }
   }
}
